import 'package:elephant_fish/http/request/base_request.dart';
import 'package:elephant_fish/http/request/safes_gold_request.dart';
import 'package:elephant_fish/model/user_info_entity.dart';
import 'package:elephant_fish/page/bag_all_page.dart';
import 'package:elephant_fish/page/bag_liang_page.dart';
import 'package:elephant_fish/page/bag_mount_page.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class BagPage extends StatefulWidget {
  final UserInfoEntity userInfoEntity;
  const BagPage({Key key, this.userInfoEntity}) : super(key: key);

  @override
  _BagPageState createState() => _BagPageState();
}

class _TabData {
  final Widget tab;
  final Widget body;
  _TabData({this.tab, this.body});
}

final _tabDataList = <_TabData>[
  _TabData(tab: Text('综合'), body: BagAllPage(categoryName: '综合',)),
  _TabData(tab: Text('靓号'), body: BagLiangPage(categoryName: '靓号',)),
  _TabData(tab: Text('坐骑'), body: BagMountPage(categoryName:'坐骑')),
];


class _BagPageState extends State<BagPage> {
  final tabBarList = _tabDataList.map((item) => item.tab).toList();
  final tabBarViewList = _tabDataList.map((item) => item.body).toList();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xff140c3d),
      appBar: AppBar(
        centerTitle: true,
        leading: GestureDetector(
          child: Icon(Icons.arrow_back_ios,size: SizeUtil.px(32),color: Color(0xffffffff),),
          onTap: (){
            Navigator.pop(context);
          },
        ),
        actions: [
          Align(
            alignment: Alignment.centerRight,
            child: Padding(padding: EdgeInsets.only(right: SizeUtil.px(30)),
              child:Text((int.parse(widget.userInfoEntity.currentGold) / 10000).toString() + "万",style: TextStyle(fontSize: SizeUtil.px(32),color: Color(0xfff3f3f3)),),

            ),
          )
        ],
        backgroundColor: Color(0xff140c3d),
        title: Text('背包',style: TextStyle(fontSize: SizeUtil.px(32),color: Color(0xfff5f5f5)),),
      ),
      body: DefaultTabController(
        length: tabBarList.length,
        child: Scaffold(
          appBar: AppBar(
            centerTitle: true,
            automaticallyImplyLeading: false,
            backgroundColor: Color(0xff140c3d),
            title:
                TabBar(
                  // isScrollable: true, //可滚动
                  indicatorColor: Color(0xffff215d), //指示器的颜色
                  labelColor: Color(0xffffffff), //选中文字颜色
                  unselectedLabelColor: Color(0xffffffff), //为选中文字颜色
                  isScrollable: false,
                  unselectedLabelStyle: TextStyle(
                    fontSize: SizeUtil.px(32),
                  ),
                  labelStyle: TextStyle(
                    fontSize: SizeUtil.px(32),
                  ),
                  // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
                  tabs: tabBarList,
                ),

          ),
          body:
          TabBarView(
              children: tabBarViewList
          ),
        ),
      ),
    );
  }


}
